reverse a linked list hackerrank solution in python